package com.hk.sync.address.component;

import org.springframework.stereotype.Component;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class MailComponent {
    private static final int CPU_NUM = Runtime.getRuntime().availableProcessors();
    private static final double blockingCoefficient = 0.5;//阻塞系数
    private static final int poolSize = (int) (CPU_NUM / (1 - blockingCoefficient));
    private final ThreadPoolExecutor mProcessThreadPool = new ThreadPoolExecutor(poolSize, 2 * poolSize, 500L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    //发送邮件
    public void sendMail() {
        mProcessThreadPool.submit(new MailSend("from", "to", "content"));
    }

    private class MailSend implements Runnable {
        private String form;
        private String to;
        private String content;

        public MailSend(String form, String to, String content) {
            this.form = form;
            this.to = to;
            this.content = content;
        }


        @Override
        public void run() {
            send();
        }
    }

    private String send() {
        System.out.println("hello mial");
        return "";
    }
}
